package route

import (
	"time"

	"gitee.com/jiebaiyou/formflow/api/controller"
	"gitee.com/jiebaiyou/formflow/bootstrap"
	"gitee.com/jiebaiyou/formflow/pkg/storage/redis"
	"gitee.com/jiebaiyou/formflow/pkg/storage/sqlite"
	"gitee.com/jiebaiyou/formflow/repository"
	"gitee.com/jiebaiyou/formflow/service"
	"github.com/gin-gonic/gin"
)

// NewTaskRouter 创建并配置任务相关的API路由
func NewTaskRouter(env *bootstrap.Config, timeout time.Duration, db sqlite.DB, cache redis.Database, group *gin.RouterGroup) {
	// 初始化任务仓储
	tr := repository.NewTaskRepository(db, cache)
	// 初始化任务服务
	ts := service.NewTaskService(tr, timeout)
	// 初始化任务控制器
	tc := &controller.TaskController{
		TaskService: ts,
	}

	// 注册获取任务列表路由
	group.GET("/tasks", tc.Fetch)
	// 注册创建任务路由
	group.POST("/tasks", tc.Create)
}
